<?php
class Model_OrderDetail extends Zend_Db_Table_Abstract
{
    protected $_name = 'order_detail';

    public function getPaginator($filters = array(), $sort = null, $page = 1, $rowCount = null)
    {
        // get select query
        $select = $this->select ();
        if ($filters != null)
        {
            if (is_array ( $filters ))
            {
                foreach ( $filters as $key => $val )
                    $select->where ( $key, $val );
            }
            else
            {
                $select->where ( $filters );
            }
        }
        
        if ($sort != null)
            $select->order ( $sort );
            
        // get adapter
        $adapter = new Zend_Paginator_Adapter_DbTableSelect ( $select );
        
        // get paginator
        $paginator = new Zend_Paginator ( $adapter );
        $paginator->setItemCountPerPage ( $rowCount );
        $paginator->setCurrentPageNumber ( $page );
        
        return $paginator;
    }

    public function getList($filters = array(), $sort = null, $page = null, $rowCount = null)
    { 
        $select = $this->select ();
        if ($filters != null)
        {
            if (is_array ( $filters ))
            {
                foreach ( $filters as $key => $val )
                    $select->where ( $key, $val );
            }
            else
            {
                $select->where ( $filters );
            }
        }
        
        if ($page != null)
            $select->limitPage ( $page, $rowCount );
        
        if ($sort != null)
            $select->order ( $sort );
            
        return $this->fetchAll ( $select );
    }
    
    public function createOrderDetail($orderID, $productID, $price, $quantity)
    {
        // create a new row in the table
        $row = $this->createRow ();
       
        // set the row data
        $row->order_id = $orderID;
        $row->product_id = $productID;
        $row->price = $price;
        $row->quantity = $quantity;
        
        // save the new row
        $row->save ();
    }
}
?>
